# -*- coding:utf-8 -*-

## =====================================================================
## Copyright (C) 2007-2011  Jean-Philippe GOLAY
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## =====================================================================


from Tkinter import *
import Pmw
import time
from tkMessageBox import *

from Persistance import *
from iCalendar import CalendarGUI
from iNotes import NotesGUI
from iStaff import StaffListGUI
from iProduct import ProductListGUI
from iTime import TimePopupGUI


class TechnicalGUI(Toplevel):
	def __init__(self, parent=None, balloon=None, path=None, log=None):
		Toplevel.__init__(self, parent)
		self.parent=parent
		self.grab_set()
		self.transient(self.master)
		self.resizable(width=False, height=False)
		self.title(u"Planning Technique de la résidence")
		self.balloon=balloon
		self.imgSearch=PhotoImage(file="img/search_icon.gif")
		self.imgNotes=PhotoImage(file="img/edit.gif")
		self.imgSave=PhotoImage(file="img/save_icon.gif")
		self.imgDelete=PhotoImage(file="img/delete_icon.gif")
		self.imgCalendar=PhotoImage(file="img/calendar.gif")
		self.imgTime=PhotoImage(file="img/time_icon.gif")
		self.hoursListCB = Glob.HOURS_LIST
		self.minutesListCB = Glob.MINUTES_LIST
		self.path=path
		self.log=log
		# Afficher un icon personnalisé
		try:
			if os.name =="posix":
				img = PhotoImage(file=self.path+"/icons/Technical-icon.gif")
				self.tk.call("wm", "iconphoto", self._w, img)
			else:
				self.iconbitmap(default=self.path+"/icons/Technical-icon.gif")
		except TclError:
			self.log.warning("Le window manager ne supporte pas l'icône que je veux lui mettre...")
		self.log.info("\tTechnicalGUI\tStart")
		self.makeTechnical()

	# DEBUT de la gestion du module Technical ------------------------------------------------------------------------------------------------------
	def clearFieldTechnical(self):
		# Mise a zéro des champs
		self.technicalValues[0].set("")
		self.technicalValues[1].set("")
		self.technicalValues[2].set(u"EA")
		self.technicalValues[3].set("")
		self.technicalValues[4].set(time.strftime("%d/%m/%Y" ,time.localtime()))
		self.technicalValues[5].set("")
		self.technicalValues[6].set("")
		self.technicalValues[7].set("")
		self.technicalValues[8].set("")
		self.technicalValues[9].set("")
		self.technicalValues[10].set("")
		self.technicalValues[11].set("")
		self.technicalValues[12].set("")
		# Remise à zéro des ComboBox
		self.technicalStatusCB.selectitem(0)
		self.hourRequestTechnicalCB.selectitem(0)
		self.minRequestTechnicalCB.selectitem(0)
		self.hourFinishTechnicalCB.selectitem(0)
		self.minFinishTechnicalCB.selectitem(0)
		self.hourCheckedTechnicalCB.selectitem(0)
		self.minCheckedTechnicalCB.selectitem(0)
		self.technicalHourRequest=StringVar()
		self.technicalMinuteRequest=StringVar()
		self.technicalHourFinish=StringVar()
		self.technicalMinuteFinish=StringVar()
		self.technicalHourChecked=StringVar()
		self.technicalMinuteChecked=StringVar()
		self.listObject=[Product, Stay, Stay, Stay]
		hour = time.strftime("%H" ,time.localtime())
		minute = time.strftime("%M" ,time.localtime())
		# Affichage de l'heure dans la ComboBox 
		count = 0
		for h in self.hoursListCB:
			if h == hour: self.hourRequestTechnicalCB.selectitem(count)
			count+=1
		# Affichage des minutes dans la ComboBox
		count = 0
		for m in self.minutesListCB:
			if m == minute: self.minRequestTechnicalCB.selectitem(count)
			count+=1
		# Mise à jour des variables heure et minutes
		self.technicalHourRequest.set(hour)
		self.technicalMinuteRequest.set(minute)

	def selectTechnical(self, event):
		self.clearFieldTechnical()
		if self.listTechnical.get(0)!="":
			result = Technical.select(Technical.q.id==self.idListTechnical[int(self.listTechnical.curselection()[0])])
			for row in result:
				self.selectedTechnical = row
			self.listObject[0]=self.selectedTechnical.product
			self.listObject[1]=self.selectedTechnical.requestByTech
			self.listObject[2]=self.selectedTechnical.answerBy
			self.listObject[3]=self.selectedTechnical.solvingBy
			if self.selectedTechnical.product != None:self.technicalValues[0].set(self.listObject[0].number+" - "+self.listObject[0].designation)
			if self.selectedTechnical.requestByTech != None:self.technicalValues[3].set(self.listObject[1].fname+" - "+self.listObject[1].lname)
			if self.selectedTechnical.answerBy != None:self.technicalValues[6].set(self.listObject[2].fname+" - "+self.listObject[2].lname)
			if self.selectedTechnical.solvingBy != None:self.technicalValues[9].set(self.listObject[3].fname+" - "+self.listObject[3].lname)
			if self.selectedTechnical.notes != None:self.technicalValues[12].set(self.selectedTechnical.notes)
			if self.selectedTechnical.designation != None:self.technicalValues[1].set(self.selectedTechnical.designation)
			if self.selectedTechnical.status != None:self.technicalValues[2].set(self.selectedTechnical.status)
			# Affichage du status dans la ComboBox
			status = ((u"EA", 0),(u"TR", 1),(u"EC", 2),(u"AV", 3),(u"VU", 4),(u"LI", 5),)
			for n in status:
				if n[0] == self.selectedTechnical.status: self.technicalStatusCB.selectitem(n[1])
			if self.selectedTechnical.request != None:
				# Affichage de la date de Demande
				self.technicalValues[4].set(self.selectedTechnical.request.strftime("%d/%m/%Y"))
				# Affichage de l'heure dans la ComboBox 
				count = 0
				for h in self.hoursListCB:
					if h == self.selectedTechnical.request.strftime("%H"): self.hourRequestTechnicalCB.selectitem(count)
					count+=1
				# Affichage des minutes dans la ComboBox
				count = 0
				for m in self.minutesListCB:
					if m == self.selectedTechnical.request.strftime("%M"): self.minRequestTechnicalCB.selectitem(count)
					count+=1
				# Mise à jour des variables heure et minutes
				self.technicalHourRequest.set(self.selectedTechnical.request.strftime("%H"))
				self.technicalMinuteRequest.set(self.selectedTechnical.request.strftime("%M"))
			if self.selectedTechnical.answer != None:
				# Affichage de la date de Effectué
				self.technicalValues[7].set(self.selectedTechnical.answer.strftime("%d/%m/%Y"))
				# Affichage de l'heure dans la ComboBox 
				count = 0
				for h in self.hoursListCB:
					if h == self.selectedTechnical.answer.strftime("%H"): self.hourFinishTechnicalCB.selectitem(count)
					count+=1
				# Affichage des minutes dans la ComboBox
				count = 0
				for m in self.minutesListCB:
					if m == self.selectedTechnical.answer.strftime("%M"): self.minFinishTechnicalCB.selectitem(count)
					count+=1
				# Mise à jour des variables heure et minutes
				self.technicalHourFinish.set(self.selectedTechnical.answer.strftime("%H"))
				self.technicalMinuteFinish.set(self.selectedTechnical.answer.strftime("%M"))
			if self.selectedTechnical.solving != None:
				# Affichage de la date de Verifié
				self.technicalValues[10].set(self.selectedTechnical.solving.strftime("%d/%m/%Y"))
				# Affichage de l'heure dans la ComboBox 
				count = 0
				for h in self.hoursListCB:
					if h == self.selectedTechnical.solving.strftime("%H"): self.hourCheckedTechnicalCB.selectitem(count)
					count+=1
				# Affichage des minutes dans la ComboBox
				count = 0
				for m in self.minutesListCB:
					if m == self.selectedTechnical.solving.strftime("%M"): self.minCheckedTechnicalCB.selectitem(count)
					count+=1
				# Mise à jour des variables heure et minutes
				self.technicalHourChecked.set(self.selectedTechnical.solving.strftime("%H"))
				self.technicalMinuteChecked.set(self.selectedTechnical.solving.strftime("%M"))
			# activation du bouton supprimer
			self.deleteTechnicalBt.config(state=NORMAL)

	def setTechnical(self, e):
			result = Technical.select(Technical.q.id==int(e.technicalID))
			for row in result:
				self.selectedTechnical = row
			self.listObject[0]=self.selectedTechnical.product
			self.listObject[1]=self.selectedTechnical.requestByTech
			self.listObject[2]=self.selectedTechnical.answerBy
			self.listObject[3]=self.selectedTechnical.solvingBy
			if self.selectedTechnical.product != None:self.technicalValues[0].set(self.listObject[0].number+" - "+self.listObject[0].designation)
			if self.selectedTechnical.requestByTech != None:self.technicalValues[3].set(self.listObject[1].fname+" - "+self.listObject[1].lname)
			if self.selectedTechnical.answerBy != None:self.technicalValues[6].set(self.listObject[2].fname+" - "+self.listObject[2].lname)
			if self.selectedTechnical.solvingBy != None:self.technicalValues[9].set(self.listObject[3].fname+" - "+self.listObject[3].lname)
			if self.selectedTechnical.notes != None:self.technicalValues[12].set(self.selectedTechnical.notes)
			if self.selectedTechnical.designation != None:self.technicalValues[1].set(self.selectedTechnical.designation)
			if self.selectedTechnical.status != None:self.technicalValues[2].set(self.selectedTechnical.status)
			# Affichage du status dans la ComboBox
			status = ((u"EA", 0),(u"TR", 1),(u"EC", 2),(u"AV", 3),(u"VU", 4),(u"LI", 5),)
			for n in status:
				if n[0] == self.selectedTechnical.status: self.technicalStatusCB.selectitem(n[1])
			if self.selectedTechnical.request != None:
				# Affichage de la date de Demande
				self.technicalValues[4].set(self.selectedTechnical.request.strftime("%d/%m/%Y"))
				# Affichage de l'heure dans la ComboBox 
				count = 0
				for h in self.hoursListCB:
					if h == self.selectedTechnical.request.strftime("%H"): self.hourRequestTechnicalCB.selectitem(count)
					count+=1
				# Affichage des minutes dans la ComboBox
				count = 0
				for m in self.minutesListCB:
					if m == self.selectedTechnical.request.strftime("%M"): self.minRequestTechnicalCB.selectitem(count)
					count+=1
				# Mise à jour des variables heure et minutes
				self.technicalHourRequest.set(self.selectedTechnical.request.strftime("%H"))
				self.technicalMinuteRequest.set(self.selectedTechnical.request.strftime("%M"))
			if self.selectedTechnical.answer != None:
				# Affichage de la date de Effectué
				self.technicalValues[7].set(self.selectedTechnical.answer.strftime("%d/%m/%Y"))
				# Affichage de l'heure dans la ComboBox 
				count = 0
				for h in self.hoursListCB:
					if h == self.selectedTechnical.answer.strftime("%H"): self.hourFinishTechnicalCB.selectitem(count)
					count+=1
				# Affichage des minutes dans la ComboBox
				count = 0
				for m in self.minutesListCB:
					if m == self.selectedTechnical.answer.strftime("%M"): self.minFinishTechnicalCB.selectitem(count)
					count+=1
				# Mise à jour des variables heure et minutes
				self.technicalHourFinish.set(self.selectedTechnical.answer.strftime("%H"))
				self.technicalMinuteFinish.set(self.selectedTechnical.answer.strftime("%M"))
			if self.selectedTechnical.solving != None:
				# Affichage de la date de Verifié
				self.technicalValues[10].set(self.selectedTechnical.solving.strftime("%d/%m/%Y"))
				# Affichage de l'heure dans la ComboBox 
				count = 0
				for h in self.hoursListCB:
					if h == self.selectedTechnical.solving.strftime("%H"): self.hourCheckedTechnicalCB.selectitem(count)
					count+=1
				# Affichage des minutes dans la ComboBox
				count = 0
				for m in self.minutesListCB:
					if m == self.selectedTechnical.solving.strftime("%M"): self.minCheckedTechnicalCB.selectitem(count)
					count+=1
				# Mise à jour des variables heure et minutes
				self.technicalHourChecked.set(self.selectedTechnical.solving.strftime("%H"))
				self.technicalMinuteChecked.set(self.selectedTechnical.solving.strftime("%M"))
			# activation du bouton supprimer
			self.deleteTechnicalBt.config(state=NORMAL)

	def setDateTime(self, e):
		self.technicalValues[4].set(e.date)
		result=Product.select(Product.q.id==int(e.productID))
		for row in result:
			self.listObject[0]=row
			self.technicalValues[0].set(self.listObject[0].number+" - "+self.listObject[0].designation)

	def searchTechnical(self, event=None):
		if self.searchTechnicalValue.get() != "":
			self.listTechnical.delete(0,END)
			self.idListTechnical = []
			result = Technical.select(Technical.q.designation.startswith(self.searchTechnicalValue.get().encode("utf-8")), orderBy=Technical.q.request)
			for row in result:
				self.listTechnical.insert(END, str(row.id)+" - "+row.product.place.company+" - "+row.product.number+" - "+row.product.designation+" - "+row.designation+" - Demande : "+row.request.strftime("%d/%m/%Y %H:%M")+" Etat : "+row.status)
				self.idListTechnical.append(row.id)
		else:
			self.listTechnical.delete(0,END)
			self.idListTechnical = []
			result = Technical.select(orderBy=Technical.q.request)
			for row in result:
				self.listTechnical.insert(END, str(row.id)+" - "+row.product.place.company+" - "+row.product.number+" - "+row.product.designation+" - "+row.designation+" - Demande : "+row.request.strftime("%d/%m/%Y %H:%M")+" Etat : "+row.status)
				self.idListTechnical.append(row.id)

	def makeTechnical(self):
		leftFrame = Frame(self)
		# Fiche Ménage  (présentation colonne de gauche)
		Label(leftFrame, text=u"Intervention Technique").pack(side=TOP, fill=X)
		# Création des champs a renseigner pour un object Technical
		technicalStatusListCB = (u"En attente", u"Transmis", u"En cours", u"A vérifié", u"Verifié ok", u"Litige") 
		technicalLabels = (u"Produit", u"Tâche", u"Avancement", u"Demandé par", u"Date", u"Heure", u"Pris en charge par", u"Date", u"Heure", u"Résolu par", u"Date", u"Heure",u"Notes")
		self.technicalValues = [StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar(), StringVar()]
		count = 0
		for name in technicalLabels:
			f = Frame(leftFrame)
			Label(f, width=16, text=name, anchor=W).pack(side=LEFT)
			if count == 0: # Produit (product)
				Entry(f, textvariable=self.technicalValues[count], width=21, state=DISABLED, bd=0, disabledforeground="black").pack(side=LEFT, fill=X)
				myProduct=Button(f, image=self.imgSearch, command=lambda x=self.technicalValues[count]:self.ctrlListProduct(x), padx=4, pady=1)
				myProduct.pack(side=RIGHT)
				self.balloon.bind(myProduct, u"Séléctionner un Produit")
			elif count == 2: # Avancement (status -  CB)
				self.technicalStatusCB=Pmw.ComboBox(f, selectioncommand=self.technicalStatus, scrolledlist_items=technicalStatusListCB, listheight=140)
				self.technicalStatusCB._entryfield._entryFieldEntry.config( width=21)
				self.technicalStatusCB.pack(side=LEFT, fill=X)
				self.technicalStatusCB.selectitem(0)
				self.technicalValues[count].set(u"EA")
			elif count == 3: # Demandé par (Staff - requestByClean)
				Entry(f, textvariable=self.technicalValues[count], width=21, state=DISABLED, bd=0, disabledforeground="black").pack(side=LEFT, fill=X)
				myRequestBy=Button(f, image=self.imgSearch, command=lambda x=self.technicalValues[count]:self.ctrlListStaff(x,1), padx=4, pady=1)
				myRequestBy.pack(side=RIGHT)
				self.balloon.bind(myRequestBy, u"Séléctionner un employé")
			elif count == 4: # Demande date (request)
				Entry(f, textvariable=self.technicalValues[count], width=21).pack(side=LEFT, fill=X)
				myCal1=Button(f, image=self.imgCalendar, command=lambda x=self.technicalValues[count]:self.ctrlCalendar(x), padx=4, pady=1)
				myCal1.pack(side=LEFT)
				self.balloon.bind(myCal1, u"Calendrier")
			elif count == 5: # Demande hour (request)
				hStartLb1=Label(f, width=2, text="H", anchor=W)
				hStartLb1.pack(side=LEFT)
				self.balloon.bind(hStartLb1, u"Heure")
				self.hourRequestTechnicalCB=Pmw.ComboBox(f, selectioncommand=self.technicalHourRequest, scrolledlist_items=self.hoursListCB, listheight=100)
				self.hourRequestTechnicalCB._entryfield._entryFieldEntry.config( width = 3)
				self.hourRequestTechnicalCB.pack(side=LEFT)
				mStartLb1=Label(f, width=3, text="mn", anchor=W)
				mStartLb1.pack(side=LEFT)
				self.balloon.bind(mStartLb1, u"minutes")
				self.minRequestTechnicalCB=Pmw.ComboBox(f, selectioncommand=self.technicalMinuteRequest, scrolledlist_items=self.minutesListCB, listheight=100)
				self.minRequestTechnicalCB._entryfield._entryFieldEntry.config( width = 3)
				self.minRequestTechnicalCB.pack(side=LEFT)
				# Menu Time
				myTime1=Button(f, image=self.imgTime, padx=1, pady=1)
				myTime1.pack(side=RIGHT)
				myTime1.bind("<ButtonRelease-1>",self.ctrlTimeNow1)
				self.balloon.bind(myTime1, u"Séléctionner une heure")
			elif count == 6: # Effectué par (Staff - answerBy)
				Entry(f, textvariable=self.technicalValues[count], width=21, state=DISABLED, bd=0, disabledforeground="black").pack(side=LEFT, fill=X)
				myFinishBy=Button(f, image=self.imgSearch, command=lambda x=self.technicalValues[count]:self.ctrlListStaff(x,2), padx=4, pady=1)
				myFinishBy.pack(side=RIGHT)
				self.balloon.bind(myFinishBy, u"Séléctionner un employé")
			elif count == 7: # Effectué date (answer)
				Entry(f, textvariable=self.technicalValues[count], width=21).pack(side=LEFT, fill=X)
				myCal2=Button(f, image=self.imgCalendar, command=lambda x=self.technicalValues[count]:self.ctrlCalendar(x), padx=4, pady=1)
				myCal2.pack(side=LEFT)
				self.balloon.bind(myCal2, u"Calendrier")
			elif count == 8: # Effectué hour (answer)
				hStartLb2=Label(f, width=2, text="H", anchor=W)
				hStartLb2.pack(side=LEFT)
				self.balloon.bind(hStartLb2, u"Heure")
				self.hourFinishTechnicalCB=Pmw.ComboBox(f, selectioncommand=self.technicalHourFinish, scrolledlist_items=self.hoursListCB, listheight=100)
				self.hourFinishTechnicalCB._entryfield._entryFieldEntry.config( width = 3)
				self.hourFinishTechnicalCB.pack(side=LEFT)
				mStartLb2=Label(f, width=3, text="mn", anchor=W)
				mStartLb2.pack(side=LEFT)
				self.balloon.bind(mStartLb2, u"minutes")
				self.minFinishTechnicalCB=Pmw.ComboBox(f, selectioncommand=self.technicalMinuteFinish, scrolledlist_items=self.minutesListCB, listheight=100)
				self.minFinishTechnicalCB._entryfield._entryFieldEntry.config( width = 3)
				self.minFinishTechnicalCB.pack(side=LEFT)
				# Menu Time
				myTime2=Button(f, image=self.imgTime, padx=1, pady=1)
				myTime2.pack(side=RIGHT)
				myTime2.bind("<ButtonRelease-1>",self.ctrlTimeNow2)
				self.balloon.bind(myTime2, u"Séléctionner une heure")
			elif count == 9: # Vérifié par (Staff - solvingBy)
				Entry(f, textvariable=self.technicalValues[count], width=21, state=DISABLED, bd=0, disabledforeground="black").pack(side=LEFT, fill=X)
				myCheckBy=Button(f, image=self.imgSearch, command=lambda x=self.technicalValues[count]:self.ctrlListStaff(x,3), padx=4, pady=1)
				myCheckBy.pack(side=RIGHT)
				self.balloon.bind(myCheckBy, u"Séléctionner un employé")
			elif count == 10: # Vérifié date (solving)
				Entry(f, textvariable=self.technicalValues[count], width=21).pack(side=LEFT, fill=X)
				myCal3=Button(f, image=self.imgCalendar, command=lambda x=self.technicalValues[count]:self.ctrlCalendar(x), padx=4, pady=1)
				myCal3.pack(side=LEFT)
				self.balloon.bind(myCal3, u"Calendrier")
			elif count == 11: # Vérifié hour (solving)
				hStartLb3=Label(f, width=2, text="H", anchor=W)
				hStartLb3.pack(side=LEFT)
				self.balloon.bind(hStartLb3, u"Heure")
				self.hourCheckedTechnicalCB=Pmw.ComboBox(f, selectioncommand=self.technicalHourChecked, scrolledlist_items=self.hoursListCB, listheight=100)
				self.hourCheckedTechnicalCB._entryfield._entryFieldEntry.config( width = 3)
				self.hourCheckedTechnicalCB.pack(side=LEFT)
				mStartLb3=Label(f, width=3, text="mn", anchor=W)
				mStartLb3.pack(side=LEFT)
				self.balloon.bind(mStartLb3, u"minutes")
				self.minCheckedTechnicalCB=Pmw.ComboBox(f, selectioncommand=self.technicalMinuteChecked, scrolledlist_items=self.minutesListCB, listheight=100)
				self.minCheckedTechnicalCB._entryfield._entryFieldEntry.config( width = 3)
				self.minCheckedTechnicalCB.pack(side=LEFT) 
				# Menu Time
				myTime3=Button(f, image=self.imgTime, padx=1, pady=1)
				myTime3.pack(side=RIGHT)
				myTime3.bind("<ButtonRelease-1>",self.ctrlTimeNow3)
				self.balloon.bind(myTime3, u"Séléctionner une heure")
			elif count == 12: # Notes
				Entry(f, textvariable=self.technicalValues[count], width=21).pack(side=LEFT, fill=X)
				myNotes=Button(f, image=self.imgNotes, command=lambda x=self.technicalValues[count]:self.ctrlNotes(x,u"Notes intervention technique"), padx=4, pady=1)
				myNotes.pack(side=RIGHT)
				self.balloon.bind(myNotes, u"Détails de la note")
			else:
				Entry(f, textvariable=self.technicalValues[count], width=24).pack(side=LEFT, fill=X)
			f.pack(side=TOP, fill=X)
			count += 1
		# Boutons enregistrement (new ou modify) et suppression
		s = Frame(leftFrame) 
		self.saveTechnicalBt=Button(s, image=self.imgSave, command=self.createTechnical)
		self.saveTechnicalBt.bind("<Return>", self.createTechnical)
		self.saveTechnicalBt.pack(side=LEFT)
		self.balloon.bind(self.saveTechnicalBt, u"Enregistrer")
		self.deleteTechnicalBt=Button(s, image=self.imgDelete, command=self.deleteTechnical, state=DISABLED)
		self.deleteTechnicalBt.bind("<Return>", self.deleteTechnical)
		self.deleteTechnicalBt.pack(side=LEFT)
		self.balloon.bind(self.deleteTechnicalBt, u"Supprimer")
		s.pack(side=TOP, fill=X)
		leftFrame.pack(side=LEFT, fill=X)
		# Liste des Occupation existants (présentation colonne de droite)
		rightFrame = Frame(self) 
		Label(rightFrame, text=u"Liste des Interventions plannifiées").pack(side=TOP, fill=X)
		self.searchTechnicalValue = StringVar()
		self.searchTechnicalEt = Entry(rightFrame,  width=93, textvariable=self.searchTechnicalValue, relief=GROOVE)
		self.searchTechnicalEt.bind("<KeyRelease>", self.searchTechnical)
		self.searchTechnicalEt.pack(side=TOP, fill=X)
		self.balloon.bind(self.searchTechnicalEt, u"Saisir les premières lettres d'une Intervention\npour une recherche plus précise,\nla liste est classée par date de demande.")
		s = Frame(rightFrame) 
		scrollbar = Scrollbar(s)
		scrollbar.pack(side=RIGHT, fill=Y)
		self.listTechnical = Listbox(s)
		self.listTechnical.config(yscrollcommand=scrollbar.set, width=90, selectmode=SINGLE, height=17)
		self.listTechnical.bind("<ButtonRelease-1>",self.selectTechnical)
		scrollbar.config(command=self.listTechnical.yview)
		self.listTechnical.pack()
		self.balloon.bind(self.listTechnical, u"Séléctionner une Intervention\npour la visualiser ou la modifier.")
		s.pack(side=TOP, fill=X)
		rightFrame.pack(side=RIGHT, fill=BOTH)
		# Initialisation
		self.clearFieldTechnical()
		self.searchTechnical()

	def ctrlTimeNow1(self,event):
		varHour=[self.technicalHourRequest, self.technicalMinuteRequest, self.hourRequestTechnicalCB, self.minRequestTechnicalCB] 
		TimePopupGUI(self, event=event, field=self.technicalValues[5], varHour=varHour, log=self.log, path=self.path)

	def ctrlTimeNow2(self,event):
		varHour=[self.technicalHourFinish, self.technicalMinuteFinish, self.hourFinishTechnicalCB, self.minFinishTechnicalCB]
		TimePopupGUI(self, event=event, field=self.technicalValues[8], varHour=varHour, log=self.log, path=self.path)

	def ctrlTimeNow3(self,event):
		varHour=[self.technicalHourChecked, self.technicalMinuteChecked, self.hourCheckedTechnicalCB, self.minCheckedTechnicalCB]
		TimePopupGUI(self, event=event, field=self.technicalValues[11], varHour=varHour, log=self.log, path=self.path)

	def ctrlCalendar(self,field):
		CalendarGUI(field=field, log=self.log, path=self.path)

	def ctrlNotes(self,field,title):
		NotesGUI(field=field,title=title, log=self.log, path=self.path)

	def ctrlListProduct(self,field):
		ProductListGUI(balloon=self.balloon, field=field, index=0, listObject=self.listObject, log=self.log, path=self.path)

	def ctrlListStaff(self,field,index):
		StaffListGUI(balloon=self.balloon, field=field, index=index, listObject=self.listObject, log=self.log, path=self.path)

	def technicalStatus(self, value):
		status = ((u"EA", u"En attente"),(u"TR", u"Transmis"),(u"EC", u"En cours"),(u"AV", u"A vérifié"),(u"VU", u"Verifié ok"),(u"LI", u"Litige"),)
		for n in status:
			if n[1] == value: self.technicalValues[2].set(n[0])

	def technicalHourRequest(self, value):
		self.technicalHourRequest.set(value)
		self.minRequestTechnicalCB.selectitem(0)
		self.minRequestTechnicalCB.invoke()

	def technicalMinuteRequest(self, value):
		self.technicalMinuteRequest.set(value)

	def technicalHourFinish(self, value):
		self.technicalHourFinish.set(value)
		self.minFinishTechnicalCB.selectitem(0)
		self.minFinishTechnicalCB.invoke()

	def technicalMinuteFinish(self, value):
		self.technicalMinuteFinish.set(value)

	def technicalHourChecked(self, value):
		self.technicalHourChecked.set(value)
		self.minCheckedTechnicalCB.selectitem(0)
		self.minCheckedTechnicalCB.invoke()

	def technicalMinuteChecked(self, value):
		self.technicalMinuteChecked.set(value)

	def getDateTimeRequestTechnical(self):
		if self.technicalValues[4].get() != "":
			date=self.technicalValues[4].get().split("/")
			d = datetime.datetime(int(date[2]), int(date[1]), int(date[0]), int(self.technicalHourRequest.get()), int(self.technicalMinuteRequest.get()), 0)
			return d
		else:
			return None

	def getDateTimeFinishTechnical(self):
		if self.technicalValues[7].get() != "":
			date=self.technicalValues[7].get().split("/")
			d = datetime.datetime(int(date[2]), int(date[1]), int(date[0]), int(self.technicalHourFinish.get()), int(self.technicalMinuteFinish.get()), 0)
			return d
		else:
			return None

	def getDateTimeCheckedTechnical(self):
		if self.technicalValues[10].get() != "":
			date=self.technicalValues[10].get().split("/")
			d = datetime.datetime(int(date[2]), int(date[1]), int(date[0]), int(self.technicalHourChecked.get()), int(self.technicalMinuteChecked.get()), 0)
			return d
		else:
			return None

	def verifyTechnical(self):
		if self.technicalValues[0].get() == "":
			showerror(u"Erreur de saisie", u"Le champ Produit est obligatoire !\nMerci de le compléter.")
			return False
		elif self.technicalValues[1].get() == "":
			showerror(u"Erreur de saisie", u"Le champ Tâche est obligatoire !\nMerci de le compléter.")
			return False
		elif self.technicalValues[3].get() == "": 
			showerror(u"Erreur de saisie", u"Le champ Demandé par est obligatoire !\nMerci de le compléter.")
			return False
		elif self.technicalValues[4].get() == "": 
			showerror(u"Erreur de saisie", u"Le champ Demande Date est obligatoire !\nMerci de le compléter.")
			return False
		elif self.technicalHourRequest.get() == "" or  self.technicalMinuteRequest.get() == "": 
			showerror(u"Erreur de saisie", u"Les champs Heures et Minutes de la Demande sont obligatoire !\nMerci de les compléter.")
			return False
		else:
			return True

	def createTechnical(self, event=None):
		if self.verifyTechnical():
			if  self.deleteTechnicalBt.config()["state"][4] == "normal":
				self.modifyTechnical()
			else:
				if askyesno(u"Enregistrement", u"Souhaitez-vous enregistrer %s comme une nouvelle interventione ?\n" % self.technicalValues[1].get()):
					Technical(product=self.listObject[0],
						designation=self.technicalValues[1].get().encode("utf-8"),
						request=self.getDateTimeRequestTechnical(),
						answer=self.getDateTimeFinishTechnical(),
						solving=self.getDateTimeCheckedTechnical(),
						status=self.technicalValues[2].get().encode("utf-8"),
						requestByTech=self.listObject[1],
						answerBy=self.listObject[2],
						solvingBy=self.listObject[3],
						notes=self.technicalValues[12].get().encode("utf-8"),
						createDate=datetime.datetime.now()
					)
					self.searchTechnical()
				self.clearFieldTechnical()

	def modifyTechnical(self, event=None): 
		if askyesno(u"Modifier", u"Souhaitez-vous modifier l'intervention %s ?" % str(self.selectedTechnical.id)):
			self.selectedTechnical.product=self.listObject[0]
			self.selectedTechnical.designation=self.technicalValues[1].get().encode("utf-8")
			self.selectedTechnical.request=self.getDateTimeRequestTechnical()
			self.selectedTechnical.answer=self.getDateTimeFinishTechnical()
			self.selectedTechnical.solving=self.getDateTimeCheckedTechnical()
			self.selectedTechnical.status=self.technicalValues[2].get().encode("utf-8")
			self.selectedTechnical.requestByTech=self.listObject[1]
			self.selectedTechnical.answerBy=self.listObject[2]
			self.selectedTechnical.solvingBy=self.listObject[3]
			self.selectedTechnical.notes=self.technicalValues[12].get().encode("utf-8")
			self.searchTechnical()
		self.deleteTechnicalBt.config(state=DISABLED)
		self.clearFieldTechnical()

	def deleteTechnical(self, event=None): 
		if askyesno(u"Suppression", u"Souhaitez-vous supprimer l'intervention %s ?\nCette opération est irréversible !" % str(self.selectedTechnical.id)):
			Technical.delete(self.selectedTechnical.id)
			self.searchTechnical()            
		self.deleteTechnicalBt.config(state=DISABLED)
		self.clearFieldTechnical()
	# FIN de la gestion du module Technical --------------------------------------------------------------------------------------------------------

#~ class TechnicalListGUI(Toplevel):
    #~ def __init__(self, parent=None, balloon=None, field=None, index=None):
        #~ Toplevel.__init__(self, parent)
        #~ self.parent=parent
        #~ self.grab_set()
        #~ self.transient(self.master)
        #~ self.resizable(width=False, height=False)
        #~ self.title(u"Liste des Articles")
        #~ self.balloon=balloon
        #~ self.field=field
        #~ self.index=index
        #~ self.makeListItem()